<?php
//Manage Categories list 
class CategoriesList{
	//Public variable available in the categories_list.tpl Smarty template 
	public $mSelectedDepartment=0;
	public $mSelectedCategory=0;
	public $mCategories;
	
	//constructor read query string parameter 
	public function __construct(){
		
		if(!isset($_GET['ProductId'])){
		//Department id exists in the query string ,we are visiting a department  
		if(isset($_GET['DepartmentId']))
			$this->mSelectedDepartment=(int)$_GET['DepartmentId'];
			else 
			trigger_error('Department Id Not set');
			
		if(isset($_GET['CategoryId'])){
			$this->mSelectedCategory=(int)$_GET['CategoryId'];
			}
		}else{
		   $continue_shopping =Link::QueryStringToArray($_SESSION['link_to_continue_shopping']);
			if(array_key_exists('DepartmentId', $continue_shopping)){
			 	$this->mSelectedDepartment=(int)$continue_shopping['DepartmentId'];
			}else{
				trigger_error('Department Id Not Set');
			}
		   if(array_key_exists('CategoryId', $continue_shopping)){
			 	$this->mSelectedCategory=(int)$continue_shopping['CategoryId'];
			 }
		
		}
	}
	
	//call bussiness tire method to List the category belongs to a department  
	public function init(){
		
		//Get the list of categories 
		$this->mCategories =Catalog::GetCategoriesInDepartment($this->mSelectedDepartment);
		
		//Create the category links in $mcategories
		for($i=0;$i< count($this->mCategories);$i++){
			$this->mCategories[$i]['link_to_category']=
			Link::ToCategory($this->mSelectedDepartment,$this->mCategories[$i]['category_id']);
			}
   
	  }
	
	
} 
